const express = require('express');
const app = express();
let name = "luomin";

const cb0 = function(req, res, next){
    console.log('CB0');
    next();
};
const cb1 = function(req, res, next){
    console.log("CB0");
    next();
};

const cb2 = function(req,res,next){
   res.send("Hello from C!");
};

app.get("/",(req,res)=>{
    res.send("Hello,world");
});

app.all("/secret",(req,res,next)=>{
    console.log(req);
    name += name;
    next();
});

app.get("/example/c",[cb0,cb1,cb2]);
/**
 * /ab+cd 匹配abcd abbcd
 */
app.get("/ab+cd",(req,res)=>{
    res.send('ab+cd');
});
app.get("/secret",(req,res) =>{
    console.log(req);
    res.send(name);
});

app.get('/render',(req,res)=>{
    res.render('index',{title:'Hey',message:'Hello there!'});
});

app.set('view engine','pug');
app.set('views','./views');


const server = app.listen(3000,()=>{
    const host = server.address();
    console.log(host);
    const port = server.address().port;
    console.log("Example app  are listening at http://%s:%s",host,port);
});